package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.CartDTO;
import com.etoak.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")

public class CartController {
    @Autowired
    CartService cartService;
    @PostMapping
    public ResultVO<Object> add(@Validated @RequestBody CartDTO dto){
        cartService.add(dto);
        return ResultVO.success();
    }
    @GetMapping
    public ResultVO<List<CartDTO>> getList(){
        List<CartDTO> list = cartService.getList();
        return ResultVO.success(list);
    }
    @DeleteMapping("/dishes/{id}")
    public ResultVO<Object> deleteDishes(@PathVariable int id){
        cartService.deleteDishes(id);
        return ResultVO.success();
    }
    @DeleteMapping
    public  ResultVO<Object> clearCart(){
        cartService.clearCart();
        return ResultVO.success();
    }
}
